<?php

namespace Admin\Controller;

/**
 * 意见反馈管理
 * @author Legend. <xcx_legender@qq.com>
 * @param
 * @return
 */

class FeedbackController extends BaseManageController {

	protected $modelName = 'Feedback';

	//工具卸载的反馈
	public function toolUninstall() {
		$model = service('FeedbackTool');
		$lists = $this->getList($model, ['type' => 'uninstall']);
		$this->_list = $lists;
		$this->display();
	}

    public function format_lists(&$lists)
    {
        // echo json_encode($lists);exit;
    }

    public function reply()
    {
        $id = I('request.id', 0, 'intval');
        $info = $this->model->where(['id' => (int)$id])->find();
        if (!$info) {
            $this->error('参数有误');
        }
        if (IS_POST) {
            !$info['uid'] && $this->error('未登录用户反馈，不能回复');

            $reply = I('reply', '', 'trim');
            !$reply && $this->error('回复不能为空');

            $official_uid = C('FEEDBACK_OFFICIAL_UID', null, 0);
            if ($official_uid) {
                // 发送私信
                event('Mail')->send($official_uid, intval($info['uid']), $reply);
                // 修改回复状态
                $this->model->save([
                    'id' => $id,
                    'replied' => 1
                ]);
                $this->success('回复成功', U('Feedback/index'));
            }
            $this->error('回复失败');
        }
        $this->assign($info);
        $this->display();
    }
}